# coding=utf-8
from django.db import models
from com.kjssoft.common.beehive.consts import GoodsConsts
from com.kjssoft.common.globals import DBTableAssist

__author__ = 'daihaibin'

#noinspection PyUnresolvedReferences
class Category(models.Model):
    uuid = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=128, unique=True)
    super_category = models.ForeignKey('beehive.Category', null=True, blank=True)

    class Meta:
        db_table = DBTableAssist.get_db_table_name('beehive_goods_category')

#noinspection PyUnresolvedReferences
class Goods(models.Model):
    """
    Every thing is Goods.
    """
    uuid        = models.IntegerField(primary_key=True, help_text='物品唯一标识符号，不可重复')
    categories  = models.ManyToManyField(Category, related_name='goods_categories', help_text='类别')
    name        = models.CharField(max_length=128, null=True, blank=True, help_text='名称')
    description = models.CharField(max_length=500, null=True, blank=True, help_text='描述')
    create_ms   = models.IntegerField(null=True, blank=True, help_text='创建时间')
    life_cycle  = models.IntegerField(default=GoodsConsts.LIFE_CYCLE_FOREVER)
    max_size    = models.IntegerField(default=GoodsConsts.MAX_SIZE_NO_LIMIT, help_text='每人最大可拥有该物品的数量,-1表示没有限制')
    prices      = models.ManyToManyField('beehive.GoodsProfile', related_name='goods_prices', null=True, blank=True, help_text='物品价格')
    rewards     = models.ManyToManyField('beehive.GoodsProfile', related_name='goods_rewards', null=True, blank=True, help_text='使用该物品获取的奖励')
    limits      = models.ManyToManyField('beehive.GoodsProfile', related_name='goods_limits', null=True, blank=True, help_text='使用该物品的限制')

    class Meta:
        db_table = DBTableAssist.get_db_table_name('beehive_goods')

#noinspection PyUnresolvedReferences
class GoodsProfile(models.Model):
    """
    物品属性描述模型，表示物品价格，物品奖励，以及物品使用限制
    """
    goods      = models.ForeignKey('beehive.Goods', related_name='price_goods', help_text='物品属性')
    size       = models.IntegerField(help_text='物品数量')
    setting_ms = models.IntegerField(null=True, blank=True, help_text='设置时间')

    def __unicode__(self):
        return '%s(%s) %s' % (self.goods.uuid, self.goods.name, self.size)

    class Meta:
        db_table = DBTableAssist.get_db_table_name('beehive_goods_profile')